﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Supersense.content;
using Supersense.db;
using System.Collections.Generic;

public partial class admin_message_list : System.Web.UI.Page
{
    public Message obj = new Message();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if ((Session["username"] == null) || (Session["username"].ToString() == ""))
        //{
        //    Response.Redirect("~/admin/login.aspx");
        //}

        if (!IsPostBack)
        {
            //Database db = new Database();
            //DataView dv = db.executedv("SELECT * FROM sup_spacenews WHERE type='news' ORDER BY settop desc, eventdate desc,id desc");
            //DataTable dt = dv.Table;
            //repeater1.DataSource = dt.DefaultView;
            //repeater1.DataBind();
            //Response.Write(this.obj.get_message_by_type(1));

            Hashtable ht = obj.pageinfo();
            int pagesize = 10;
            //AspNetPager1.RecordCount = int.Parse(ht["records"].ToString().Trim());
            AspNetPager1.FirstPageText = "首页";
            AspNetPager1.LastPageText = "末页";
            AspNetPager1.PrevPageText = "上页";
            AspNetPager1.NextPageText = "下页";
            AspNetPager1.NumericButtonCount = 5;

            AspNetPager1.PageSize = pagesize;
            AspNetPager1.RecordCount = int.Parse(ht["records"].ToString().Trim());
            this.databind();
        }


    }

    public void databind()
    {
        DataView dv = this.obj.get_message_by_type("news", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
        repeater1.DataSource = dv;
        repeater1.DataBind();
    }

    protected void Button1_ServerClick(object sender, EventArgs e)
    {
        string ids = "";
        List<string> arr = new List<string>();

        foreach (RepeaterItem rp in repeater1.Items)
        {
            CheckBox cbox = (CheckBox)rp.FindControl("cdDelete");
            HiddenField hd = (HiddenField)rp.FindControl("newsid");

            if (cbox.Checked == true)
            {
                //ids = ids + "," + hd.Value.ToString();
                arr.Add(hd.Value.ToString().Trim());
            }
            //ids = ids.Substring(0,ids.Length-1);

        }
        ids = string.Join(",", arr.ToArray());
        if (ids == "")
        {
            Response.Write("<script type='text/javascript'>alert('您执行的操作失败了，因为您没有选择任何记录！');history.go(-1);</script>");
        }
        else
        {
            News objNews = new News();
            if (objNews.delete(ids))
            {
                Response.Write("<script type='text/javascript'>alert('您执行的操作成功了!')</script>");
                Response.Write("<meta http-equiv='refresh' content='0;url=list.aspx'/>");
            }
            else
            {
                Response.Write("<script type='text/javascript'>alert('您执行的操作失败了!');history.go(-1);</script>");
            }
        }
        //ids = ids.Substring(1);
        //Response.Write(ids);
        //Response.Write(1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.databind();
        //Response.Redirect("list.aspx?page=" + AspNetPager1.CurrentPageIndex);
        //Response.Write(AspNetPager1.CurrentPageIndex);
    }
}
